/*
 * @Author: Zhouhai 497675647@qq.com
 * @Date: 2022-08-16 17:06:54
 * @LastEditors: Zhouhai 497675647@qq.com
 * @LastEditTime: 2024-04-30 10:11:32
 */
/* eslint-disable @typescript-eslint/no-unused-vars */
import PageDiv from '@/components/PageDiv';
import { Button, Space, Spin, Tabs } from 'antd';
import React, { useState } from 'react'
import BasicInfoForm from './basicInfoForm';
import GenEditTable from './editTable';
import GenInfoForm from './genInfoForm';

export type GenEditProps = {
    datas: Record<string, any>;
    submit: (data: any) => void;
    cancle: () => void;
}

const GenEdit: React.FC<GenEditProps> = (Props) => {
    const { datas, submit, cancle } = Props;
    const [loading, setLoading] = useState(false); //页面是否加载状态
    const [editdata, setEditdata] = useState<Record<string, any>>(()=>{
        return {...datas.info,columns: datas.rows}
    });


    const onValuesChange = (changedValues: any, values: any) => {
        setEditdata({ ...editdata, ...changedValues });
    }

    const onColumnChange = (changedValues: any) => {
        console.log('changedValues',changedValues);
        
        editdata.columns = changedValues;
        setEditdata(editdata);
    }

    const buttonrender = (
        <Space>
            <Button onClick={() => {
                submit(editdata)
            }}>
                提交
            </Button>
            <Button onClick={cancle}>
                返回
            </Button>
        </Space>
    )
    return (
        <Spin spinning={loading}>
            <PageDiv style={{ marginTop: "5px",padding: "0px 15px" }}>
                <Tabs defaultActiveKey="1" tabBarExtraContent={buttonrender} style={{ height: "100%" }}>
                    <Tabs.TabPane tab="基本信息" key="baseInfo">
                        <BasicInfoForm datas={datas.info} onValuesChange={onValuesChange} />
                    </Tabs.TabPane>
                    <Tabs.TabPane tab="字段信息" key="fieldInfo" style={{ height: "100%" }}>
                        <GenEditTable defaultData={datas.rows} onValuesChange={onColumnChange}/>
                    </Tabs.TabPane>
                    <Tabs.TabPane tab="生成信息" key="genInfo">
                        <GenInfoForm datas={datas.info} onValuesChange={onValuesChange} tables={datas.tables} culumn={datas.rows}/>
                    </Tabs.TabPane>
                </Tabs>
            </PageDiv>
        </Spin>
    )
}
export default GenEdit;